home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 640 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c,alt.msdos.programmer
  4. Subject: Re: Two strange C problems.
  5. Date: 7 Jan 1996 21:42:42 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4cq3ri$amp@solutions.solon.com>
  8. References: <4cojb2$qog@lugb.latrobe.edu.au> <4cq1vu$d8c@gryphon.phoenix.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <4cq1vu$d8c@gryphon.phoenix.net>,
  12. Bruce Wedding <brucew@phoenix.net> wrote:
  13. >cs102238@lux.latrobe.edu.au (Gregary John Boyles ) wrote:
  14. >>PROBLEM 2 :
  15.  
  16. >>const escape=27;
  17. >>const cr=13;
  18. >>const bs=8;
  19.  
  20. >In C++, this is ok.  In C, you have to use:
  21. >#define ESC 27
  22. >#define CR 13
  23.  
  24. This is untrue.
  25.  
  26. Rather, it would be true if you wanted to use escape, cr, or bs as sizes
  27. for array variables, initializers of static or global variables, as case
  28. values, or in other contexts where a constant is required.  It appears
  29. to have nothing to do with the problem at hand.
  30.  
  31. >etc.
  32.  
  33. >>while (ch!=cr)
  34. >Then all these loops will work.
  35.  
  36. This would work with cr being a variable, as well, even if it's not a
  37. const - in fact, the poster specifically *said* that that worked.
  38.  
  39. >>If I replace the 27 with \27' or the 13 with '\13' then these loops don't
  40. >>work i.e. an infinite loop results. WHY?
  41.  
  42. >Because the character will never equal those values, simple enough.
  43.  
  44. But that doesn't explain the problem, which is that \27 is 27 *OCTAL*,
  45. not decimal, and is 23 decimal, which is ASCII ETB, not ESC.  Ditto
  46. CR/VT.
  47.  
  48. >It uses the standard ASCII character set, at least in DOS.  If you
  49. >want to print those characters, just use those values.  The \
  50. >character is only used with the following chars ( ",\,n,r,f,0).  Well,
  51. >that is probably not all of them, but those are the most important.
  52. >If you want to print those characters above, do this:
  53.  
  54. You seem to have totally missed the point; \ is used with a large set of
  55. things.  To put generic characters in with it, you can use \xhex-number or
  56. \octal-number.  The \0 is a special case of \octal-number, and means,
  57. specifially, the character whose value is 0, base 8.  Conveniently, 0
  58. in octal is 0 in decimal.
  59.  
  60. >I hate to say it, but you are asking for it.  Maybe one needs to learn
  61. >the damn language so they can program sensibly and predictably.  At
  62. >least there is a standard for C.  Pascal has no standard and will
  63. >behave VERY unpredictably from system to system.
  64.  
  65. This is actually correct, however, you yourself should learn it a bit
  66. more.  (Although I admit, I'd rather you err, as you have, on the side
  67. of caution, than on the side of overconfidence.)
  68.  
  69. -s
  70. -- 
  71. Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
  72. C/Unix proto-wizard -- C/Unix questions? Send mail for help.  No, really!
  73. Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
  74. The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
  75.